/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights
 * reserved. <a>http://www.cqcis.com</a>
 */
package com.cqcis.uip.base.framework.core.impl;

import com.cqcis.uip.base.framework.common.Task;
import com.cqcis.uip.base.framework.core.RegisteredServiceContext;

/**
 * telnet客户端task上下文实现
 * 
 * @author huangmy
 * @date   2008-8-26
 */
public class DefaultTelnetClientTaskContext extends AbstractTaskContext<String> {
	private final static String END_LINE = "\r\n"; // 行尾符	
            
	public DefaultTelnetClientTaskContext(RegisteredServiceContext serviceContext, Task task) {
		super(serviceContext, task);		
	}
    	
	@Override
	public Object doBeforeWrite(Object o) {		
		return toTextline((String)o);		
	}
	
	/**
	 * 发送字符串
	 * 
	 * @param s
	 * @return
	 */
	private String toTextline(String s) {
		if (s != null && !s.endsWith(END_LINE)) {
			s = s + END_LINE;
		}
		
		return s;
	}
}
